﻿using Microsoft.Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Inovout.Web.Mvc.Owin
{
    public abstract class NotifyHandler<TNotify> : NotifyHandler
    {
        protected NotifyHandler(string notifyName)
            :base(notifyName)
        {
        }
        protected abstract Task<bool> Handle(TNotify content);
        protected override Task<bool> Handle(object content)
        {
            return this.Handle((TNotify)content);
        }
    }
    public abstract class NotifyHandler
    {
        public readonly string NotifyName;
        protected NotifyHandler(string notifyName)
        {
            this.NotifyName = notifyName;
        }
        internal Task InvokeAsync(IOwinContext context)
        {
            return null;
        }
        protected virtual Task<bool> Handle(object content)
        {
            return Task.FromResult<bool>(true);
        }
        public override int GetHashCode()
        {
            return this.NotifyName.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            NotifyHandler that = obj as NotifyHandler;
            if (that == null)
            {
                return false;
            }
            return this.NotifyName.Equals(that.NotifyName);
        }
    }
    public class Notify
    {
        public string Name { get; set; }
        public object Content { get; set; }
    }
    public static class MessageHandlers
    {
        public static readonly IList<NotifyHandler> Handlers = new List<NotifyHandler>();
        public static Task InvokeAsync(IOwinContext context)
        {

            return null;
        }
        public static bool CanInvoke(IOwinContext context)
        {
            return true;   
     }
    }
}
